package com.ruoyi.eam.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.eam.doman.SummaryAsset;
import com.ruoyi.eam.doman.EamAsset;
import com.ruoyi.eam.doman.EamType;
import com.ruoyi.eam.mapper.DictDataMapper;
import com.ruoyi.eam.mapper.DictTypeMapper;
import com.ruoyi.eam.mapper.EamAssetMapper;
import com.ruoyi.eam.mapper.EamTypeMapper;
import com.ruoyi.eam.service.IEamTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资产类型Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-18
 */
@Service
public class EamTypeServiceImpl implements IEamTypeService
{
    @Resource
    private EamTypeMapper eamTypeMapper;


    @Resource
    private EamAssetMapper eamAssetMapper;


    @Resource
    private DictDataMapper dictDataMapper;


    /**
     * 查询资产类型
     *
     * @param typeId 资产类型主键
     * @return 资产类型
     */
    @Override
    public EamType selectEamTypeByTypeId(Long typeId)
    {
        return eamTypeMapper.selectEamTypeByTypeId(typeId);
    }

    @Override
    public List<EamType> selectDictTypeParentId() {
        return eamTypeMapper.selectDictTypeParentId();
    }

    /**
     * 查询资产类型列表
     *
     * @param eamType 资产类型
     * @return 资产类型
     */
    @Override
    public List<EamType> selectEamTypeList(EamType eamType)
    {
        List<EamType> list = eamTypeMapper.selectEamTypeList(eamType);
        SummaryAsset summaryAsset = new SummaryAsset();
        EamAsset asset = new EamAsset();
        int num = 0;
        for (EamType type : list) {
            asset.setTypeId(type.getTypeId());
            List<EamAsset> assets = eamAssetMapper.selectEamAssetList(asset);
            num = assets.size();
            //summaryAsset.setAsset(assets);
//            EamType type1 = type;
//            summaryAsset.setEamType(type1);
//            summaryAsset.setCount(Integer.toUnsignedLong(num));

//            System.out.println(num);
//            System.out.println("类型名称:"+type.getTypeName());
//            System.out.println("资产名称:"+asset.getAssetName());
//            System.out.println("总数:"+num);
            type.setSummaryAsset(summaryAsset);
        }
        return list;
    }


    /**
     * 新增资产类型
     *
     * @param eamType 资产类型
     * @return 结果
     */
    @Override
    public int insertEamType(EamType eamType)
    {
        eamType.setCreateTime(DateUtils.getNowDate());
        return eamTypeMapper.insertEamType(eamType);
    }

    /**
     * 修改资产类型
     *
     * @param eamType 资产类型
     * @return 结果
     */
    @Override
    public int updateEamType(EamType eamType)
    {
        return eamTypeMapper.updateEamType(eamType);
    }

    /**
     * 批量删除资产类型
     *
     * @param typeIds 需要删除的资产类型主键
     * @return 结果
     */
    @Override
    public int deleteEamTypeByTypeIds(Long[] typeIds)
    {
        return eamTypeMapper.deleteEamTypeByTypeIds(typeIds);
    }

    /**
     * 删除资产类型信息
     *
     * @param typeId 资产类型主键
     * @return 结果
     */
    @Override
    public int deleteEamTypeByTypeId(Long typeId)
    {
        return eamTypeMapper.deleteEamTypeByTypeId(typeId);
    }
}
